<?php
include_once("header.php");
?>
<?php
if($_POST["action"] == 1)
{
$source=$_POST["source"];
$destination=$_POST["destination"];
$domain=$_POST["domain"];
if(empty($source)) {echo "<h3>ERROR<br> Source - empty!</h3>"; include_once("alias/form_new.php"); include_once("footer.php"); die();}

//include forwading
$email="$source@$domain";

//check valid email
include_once("user/check_email.php");

//valid alias
$vForwarding=mysql_query("SELECT source,destination FROM forwardings WHERE source='$email' AND destination='$destination'");
$nForwarding=mysql_num_rows($vForwarding);
if($nForwarding > 0) {echo "Alias exit!"; include_once("alias/form_new.php"); die();}
else {
	$insForwarding=mysql_query("INSERT INTO `forwardings` (`source`, `destination`) VALUES ('$email', '$destination')");
	$aForwarding=mysql_affected_rows();
	if($aForwarding > 0){echo "<h2>Alias created!</h2><h3>New alias?</h3>"; include_once("alias/form_new.php"); die();}

}

}
else
{
include_once("alias/form_new.php");
}
?>

<br /><br />
<br /><br />
<?php
include_once("footer.php");
?>
